package org.lq.shopping.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import lombok.extern.log4j.Log4j;

@Log4j
public class PropsUtil {
	
	public static Properties loadProps(String fileName) {
		Properties properties = null;
		
		InputStream is = null;
		try {
			is  = PropsUtil.class.getClassLoader().getResourceAsStream(fileName);
			if(is == null) {
				throw new FileNotFoundException("file : "+fileName);
			}
			properties = new Properties();
			properties.load(is);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			if(is != null) {
				try {
					is.close();
				} catch (IOException e) {
					log.error("close input Stream error!",e);
				}
			}
		}
		
		return properties;
	}
	
	/**
	 * 根据指定的配置文件读取数据信息
	 * @param properties
	 * @param key
	 * @return
	 */
	public static String getString(Properties properties,String key) {
		return properties.getProperty(key);
	}

}
